/**
 * 给定一些东西，一个天平。当天平两端不超过M时，天平两端作为收益。问最大收益是多少
 * 令Dij为到i位置左边减去右边差为j时的两端之和的最大。
 * Dij = max(D[i-1][j], D[i-1][j-Ai]+Ai, D[i-1][j+Ai]+Ai)
 * 用刷表法，已知Dij的话，则Dij对D[i+1][j]、D[i+1][j-A[i+1]]、D[i+1][j+A[i+1]]有贡献
 */
#include <bits/stdc++.h>
using namespace std;

using llt = long long;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vi = vector<int>;
using vll = vector<llt>;

llt const INF = 0x1F2F3F4F5F6F7F8F;
llt const NINF = -INF;
llt const MOD = 998244353LL;

int N, M;
vector<int> A;
vector<map<int, int>> D;

int chkadd(int a, int b){
    if(-1 == a or -1 == b) return -1;
    return a + b;
}

void chkmax(int & a, int b){
    if(-1 == b) return;
    if(-1 == a or a < b) a = b;
}

void work(){
    cin >> N >> M;
    A.assign(N + 1, 0);
    for(int i=1;i<=N;++i) cin >> A[i];

    int total = accumulate(A.begin(), A.end(), 0);
    
    D.assign(N + 1, {});
    D[0][0] = 0;
    for(int i=0;i<N;++i){
        const auto & now = D[i];
        auto & nxt = D[i + 1];
        auto a = A[i + 1];
        for(const auto & p : now){
            auto it = nxt.find(p.first + a);
            if(it == nxt.end()){
                it = nxt.insert(it, {p.first + a, p.second + a});
            }else{
                it->second = max(it->second, p.second + a);
            }

            it = nxt.find(p.first);
            if(it == nxt.end()){
                it = nxt.insert(it, p);
            }else{
                it->second = max(it->second, p.second);
            }

            it = nxt.find(p.first - a);
            if(it == nxt.end()){
                it = nxt.insert(it, {p.first - a, p.second + a});
            }else{
                it->second = max(it->second, p.second + a);
            }
        }
    }

    int ans = 0;
    for(int i=-M;i<=M;++i){
        chkmax(ans, D[N][i]);
    }
    cout << ans << endl;
    return;
}


int main(){
#ifndef ONLINE_JUDGE
    freopen("z.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int nofkase = 1;
    // cin >> nofkase; 
    while(nofkase--) work();    
    return 0;
}
